/************************************************************************/
/*																		*/
/*		School Hangover Project											*/
/*																		*/
/*		IMAC 2010														*/
/*		Author : 	Helena Duchaussoy									*/
/*					Isabelle Gouwy										*/
/*					Nathalie Kuoch										*/
/*					Franck Letellier									*/
/*					Louise Pequignot									*/
/*																		*/
/*		E-mail: flo-in-underware@googlegroups.com						*/
/*																		*/
/************************************************************************/

#ifndef __ENGINE_H__
#define __ENGINE_H__

#include <cstdlib>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Timer> 
#include <osgGA/GUIEventAdapter>

#include "Singleton.h"

#include "Camera.h"
#include "DialogManager.h"
#include "ObjectManager.h"
#include "StageManager.h"
#include "AbstractStage.h"

#include "Timer.h"

#define FPS 60.

///Forward declaration save compilation time 
class ObjectManager;
class Camera;
class DialogManager;
class Timer;

class Engine: public Singleton<Engine> {

friend class Singleton<Engine>;

protected:
	Engine();
	virtual ~Engine(){clear();}

public:
	void init();
	void update();
	///brief clear the whole Engine
	void clear();

	osgViewer::Viewer& getViewer() { return m_viewer; }

	Timer* getTimer();
private: 
    ObjectManager*	m_pobjectManager;
    Camera*			m_pcamera;
    DialogManager*	m_pdialogManager;

    Timer*			m_ptimer;
	osg::Timer_t	m_lastTime;

	osgViewer::Viewer m_viewer;


};

 class UpdateCallback : public osg::NodeCallback 
    {
    public:
       virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
       {
		   Engine::getInstance().update();
		   traverse(node, nv);
       }
    };


#endif // Engine_h
